﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;

namespace BCNPCObject
{
    public class cls_PC1_BIABC_Controller
    {
        #region   Atributes

        private DataSet CMIS_Header = new CMISOutputParameter();
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private PC1_BIABC info;

        #endregion

        #region   Constructor

        public cls_PC1_BIABC_Controller()
        {
            info = new PC1_BIABC();
        }
        public cls_PC1_BIABC_Controller(PC1_BIABC Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public PC1_BIABC pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region  BCKD NPC       


        public IEnumerable<PC1_BIABC> select_PC1_BIABC(string strMadviqly)
        {
            try
            {
                CMIS2.ResetDB();                
                var q = from p in CMIS2.DB.PC1_BIABC
                        orderby p.MA_DVIQLY ascending
                        where (p.MA_DVIQLY == strMadviqly) 
                        select p;
                return q;

                //var k = from m in CMIS2.DB.PC1_BIABC
                //        orderby m.MA_SO, m.MA_DVIQLY ascending
                //        where (m.MA_DVIQLY.Contains(strMadviqly)) && (m.MA_DVIQLY != strMadviqly) && (m.MA_SO.Contains(maso)) && (!m.MA_SO.Contains("0")) && (!m.MA_SO.Contains("T"))
                //        select m;

                //var s = from n in q
                //        from nn in k
                //        select;


                if (q != null && q.Count() > 0)
                {

                    return q;
                }
                else
                    return null;


            }
            catch (Exception ex)
            {
                CMIS2.ResetDB();
                return null;
            }
        }

        public bool insert_PC1_BIABC(string strMadviqly, string strNoidung, string strSobcao)
        {
            try
            {
                PC1_BIABC objPC1_BIABC = new PC1_BIABC()
                {
                    MA_DVIQLY = strMadviqly,
                    NOI_DUNG = strNoidung,
                    SO_BCAO = strSobcao
                };
                CMIS2.DB.PC1_BIABC.InsertOnSubmit(objPC1_BIABC);
                CMIS2.DB.SubmitChanges();
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                CMIS2.ResetDB(); return false;
            }
        }

        public bool update_PC1_BIABC(string strMadviqly, string strNoidung, string strSobcao)
        {
            try
            {
                PC1_BIABC objPC1_BIABC = CMIS2.DB.PC1_BIABC.Single(c => c.MA_DVIQLY == strMadviqly);

                //objPC1_BIABC.MA_DVIQLY = strMadviqly;
                objPC1_BIABC.NOI_DUNG = strNoidung;
                objPC1_BIABC.SO_BCAO = strSobcao;

                CMIS2.DB.SubmitChanges();

                return true;
            }
            catch
            {
                CMIS2.ResetDB(); return false;
            }
        }

        #endregion
    }
}
